package com.lepu.app.fun.index.adapter;

import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.core.lib.utils.main.DateUtilBase;
import com.eyzhs.app.R;
import com.lepu.app.fun.my.bean.BeanPubContent;

public class IndexHotTopicAdapter extends BaseAdapter {

	private LayoutInflater mLayoutInflater = null;
	@SuppressWarnings("unused")
	private Context mContext = null;
	private List<BeanPubContent> mArrayList = null;

	public IndexHotTopicAdapter(Context context, List<BeanPubContent> arrayList) {
		mContext = context;
		mLayoutInflater = LayoutInflater.from(context);
		mArrayList = arrayList;
	}

	@Override
	public int getCount() {
		int size = 0;
		if (mArrayList != null && mArrayList.size() > 0) {
			size = mArrayList.size();
		}
		return size;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("InflateParams")
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {

		final ViewHolder holder;

		if (convertView == null) {
			convertView = mLayoutInflater.inflate(R.layout.index_topic_list_item, null);

			holder = new ViewHolder();

			TextView titleTextView = (TextView) convertView.findViewById(R.id.titleTextView);
			TextView timeTextView = (TextView) convertView.findViewById(R.id.timeTextView);
			TextView tagTextView = (TextView) convertView.findViewById(R.id.tagTextView);
			TextView commentCountTextView = (TextView) convertView.findViewById(R.id.commentCountTextView);
			TextView lookCountTextView = (TextView) convertView.findViewById(R.id.lookCountTextView);
			
			holder.titleTextView = titleTextView;
			holder.timeTextView = timeTextView;
			holder.tagTextView = tagTextView;
			holder.lookCountTextView = lookCountTextView;
			holder.commentCountTextView = commentCountTextView;
			
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		final BeanPubContent item = mArrayList.get(position);

		holder.titleTextView.setText(item.TopicTitle);
	    holder.tagTextView.setText(item.CategoryTitle);
	    holder.timeTextView.setText(DateUtilBase.friendly_time(item.LatestReplyTime));
	    holder.lookCountTextView.setText("· 阅读  "+item.ViewCount);
		holder.commentCountTextView.setText("· 评论  "+item.ReplyCount);
	
		return convertView;
	}

	private static class ViewHolder {

		TextView titleTextView;
		TextView timeTextView;
		TextView lookCountTextView;
		TextView commentCountTextView;
		TextView tagTextView;
	}
}
